package org.example.bookstore.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.service.impl.MailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 测试邮件发送
 * @author qzz
 */
@RestController
@Tag(name = "邮箱发送Api")
@CrossOrigin // 允许跨域请求
@RequestMapping("/mail")
public class SendMailController {

    @Autowired
    private MailServiceImpl mailService;


    /**
     * 发送文本邮件
     * @param to
     * @param subject
     * @param text
     */
    @Operation(summary = "纯文本邮件")
    @PostMapping("/sendTextMail")
    public void sendTextMail(@Parameter(name = "to", description = "邮箱地址")  String to,
                             @Parameter(name = "subject", description = "邮件名称") String subject,
                             @Parameter(name = "text", description = "邮件内容") String text){
        mailService.sendTextMailMessage(to,subject,text);
    }

    /**
     * 发送HTML邮件
     * @param to
     * @param subject
     * @param content
     */
    @Operation(summary = "html邮件")
    @PostMapping("/sendHtmlMailMessage")
    public void sendHtmlMailMessage(@Parameter(name = "to", description = "邮箱地址") String to,
                                    @Parameter(name = "subject", description = "邮件名称") String subject,
                                    @Parameter(name = "text", description = "邮件内容") String content){
        mailService.sendHtmlMailMessage(to,subject,content);
    }

    /**
     * 发送带附件的邮件
     * @param to
     * @param subject
     * @param content
     */
    @Operation(summary = "带附件的邮件")
    @PostMapping("/sendAttachmentMailMessage")
    public void sendAttachmentMailMessage(@Parameter(name = "to", description = "邮箱地址") String to,
                                          @Parameter(name = "subject", description = "邮件名称") String subject,
                                          @Parameter(name = "text", description = "邮件内容") String content,
                                          @Parameter(name = "filePath", description = "文件路径") String filePath){
        filePath="D:\\1.png";
        mailService.sendAttachmentMailMessage(to,subject,content,filePath);
    }

    @Operation(summary = "发送验证码邮件")
    @GetMapping("/emailVerification")
    public ResultVO<String> sendEmailVerification(@Parameter(name = "email", description = "邮箱地址") @RequestParam String email){
        return ResultVO.success(mailService.generateVerificationCode(email));
    }
}
